package com.jetpackmvp.data

import com.jetpackmvp.internet.RetrofitService
import kotlinx.coroutines.Dispatchers.IO
import kotlinx.coroutines.withContext
import okhttp3.RequestBody

/**
 * @author: GY.LEE
 * @date: 2019-07-11
 * @Des:
 */
class LoginRepository private constructor(private val service: RetrofitService) {

    suspend fun login(params: RequestBody) {
        withContext(IO) {
            service.doLogin(params)
        }
    }


    companion object {
        @Volatile
        private var instance: LoginRepository? = null

        fun getInstance(service: RetrofitService) =
            instance ?: synchronized(this) {
                instance
                    ?: LoginRepository(service).also { instance = it }
            }
    }


}